<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .user_box {
            height: 65px;
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
            padding: 0 15px;
            margin-bottom: 6px;
            background-color: #fff;
        }
        .user_box .user_boxl {
            width: 0;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
        }
        .user_box .user_boxl .user_img {
            width: 43px;
            height: 43px;
            border-radius: 50%;
            overflow: hidden;
            margin-right: 10px;
        }
        .user_box .user_boxl .user_img img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .user_box .user_boxl .user_name {
            color: #333;
            font-size: 16px;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            padding-right: 5px;
        }
        .user_box .user_boxr img {
            width: 15px;
        }
        .main ul li .li_box {
            height: 50px;
            line-height: 50px;
            display: -webkit-box;
            display: -webkit-flex;
            align-items: center;
            background-color: #fff;
            border-bottom: 1px solid #e8e8e8;
            padding: 0 15px 0 14px;
        }
        .main ul li:last-child .li_box {
            border-bottom: none;
        }
        .main ul li .li_box .li_boxl {
            width: 35px;
        }
        .main ul li .li_box .li_boxl img {
            width: 14px;
            display: block;
        }
        .main ul li:nth-child(1) .li_box .li_boxl img {
            width: 18px;
        }
        .main ul li:nth-child(2) .li_box .li_boxl img {
            width: 14px;
        }
        .main ul li:nth-child(3) .li_box .li_boxl img {
            width: 16px;
        }
        .main ul li:nth-child(4) .li_box .li_boxl img {
            width: 14px;
        }
        .main ul li:nth-child(5) .li_box .li_boxl img {
            width: 15px;
        }
        .main ul li:nth-child(6) .li_box .li_boxl img {
            width: 16px;
        }
        .main ul li .li_box .li_boxc {
            color: #333;
            font-size: 15px;
            flex: 1;
            -webkit-flex: 1;
            box-flex: 1;
            -webkit-box-flex: 1;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            padding-right: 5px;
        }
        .main ul li .li_box .li_boxr img {
            height: 12px;
            display: block;
        }
        .no_login{
            padding-top: 150px;
            display: none;
        }
        .no_login p {
            text-align: center;
        }
        .login_btn {
            padding:9px 20px;
            text-align: center;
            color: #fff;
            border-radius: 2px;
            background-color: #e62442;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div class="no_login">
        <p>登录后查看</p>
        <p><button class="login_btn" onclick="fnToLogin();" tapmode>立即登录</button></p>
    </div>
    <div class="has_login">
        <div class="user_box" tapmode onclick="fnPersonalData();">
            <div class="user_boxl">
                <div class="user_img">
                    <img class="user_head" src="../image/default.png">
                </div>
                <div class="user_name"></div>
            </div>
            <div class="user_boxr">
                <img src="../image/my_icon5.png">
            </div>
        </div>
        <div class="main">
            <ul>
                <!-- <li tapmode onclick="fnPackageService();">
                    <div class="li_box">
                        <div class="li_boxl">
                            <img src="../image/package2.png">
                        </div>
                        <div class="li_boxc">送包裹</div>
                        <div class="li_boxr">
                            <img src="../image/right.png">
                        </div>
                    </div>
                </li> -->
                <li tapmode onclick="fnAddressManage();">
                    <div class="li_box">
                        <div class="li_boxl">
                            <img src="../image/my_icon1.png">
                        </div>
                        <div class="li_boxc">地址管理</div>
                        <div class="li_boxr">
                            <img src="../image/right.png">
                        </div>
                    </div>
                </li>
                <li tapmode onclick="fnMyEvaluate();">
                    <div class="li_box">
                        <div class="li_boxl">
                            <img src="../image/my_icon2.png">
                        </div>
                        <div class="li_boxc">我的评价</div>
                        <div class="li_boxr">
                            <img src="../image/right.png">
                        </div>
                    </div>
                </li>
                <li tapmode onclick="fnMyOrder();">
                    <div class="li_box">
                        <div class="li_boxl">
                            <img src="../image/my_icon3.png">
                        </div>
                        <div class="li_boxc">我的订单</div>
                        <div class="li_boxr">
                            <img src="../image/right.png">
                        </div>
                    </div>
                </li>
                <li tapmode onclick="fnSellerSettled();">
                    <div class="li_box">
                        <div class="li_boxl">
                            <img src="../image/my_icon4.png">
                        </div>
                        <div class="li_boxc">商家入驻</div>
                        <div class="li_boxr">
                            <img src="../image/right.png">
                        </div>
                    </div>
                </li>
                <li tapmode onclick="fnSet();">
                    <div class="li_box">
                        <div class="li_boxl">
                            <img src="../image/my_icon5.png">
                        </div>
                        <div class="li_boxc">设置</div>
                        <div class="li_boxr">
                            <img src="../image/right.png">
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    apiready = function(){
        height = api.pageParam.height;
        fnLoginChange();

        //监听登录和退出登录
        api.addEventListener({
            name: 'loginEvent'
        }, function(ret, err) {
            if (ret) {
                fnLoginChange();
            } 
        });

        api.addEventListener({
            name: 'logoutEvent'
        }, function(ret, err) {
            if (ret) {
                fnLoginChange();
            }
        });

        //监听用户信息变化
        api.addEventListener({
            name: 'userChangeEvent'
        }, function(ret, err) {
            if (ret) {
                fnGetUser();
            }
        });

        api.addEventListener({
            name: 'openNoLoginEvent'
        }, function(ret, err) {
            if (ret) {
                user = $api.getStorage('user_data');
                if(!user) {
                    fnOpenLogin();
                }
            }
        });
    };

    // 送包裹
    function fnPackageService () {
        api.openWin({
            name: 'package',
            url: 'package.html'
        });
    };

    // 个人资料
    function fnPersonalData() {
        api.openWin({
            name: 'personal_data',
            url: 'personal_data.html'
        });
    }

    // 地址管理
    function fnAddressManage() {
        api.openWin({
            name: 'address_manage',
            url: 'address_manage.html'
        });
    }

    // 我的评价
    function fnMyEvaluate() {
        api.openWin({
            name: 'my_evaluate',
            url: 'my_evaluate.html'
        });
    }

    // 我的订单
    function fnMyOrder() {
        api.openWin({
            name: 'my_order',
            url: 'my_order.html'
        });
    }

    // 商家入驻
    function fnSellerSettled() {
        api.openWin({
            name: 'seller_settled',
            url: 'seller_settled.html'
        });
    }

    // 设置
    function fnSet() {
        api.openWin({
            name: 'set',
            url: 'set.html'
        });
    }

    function fnLoginChange() {
        user = $api.getStorage('user_data');
        if(user) {
            $('.no_login').hide();
            $('.has_login').show();
            fnGetUser();
        }else {
            $('.no_login').show();
            $('.has_login').hide();
            // fnOpenLogin();
        }
    }

    function fnToLogin() {
        api.openWin({
            name: 'login',
            url: './login.html',
        });
    }

    function fnGetUser() {
        user = $api.getStorage('user_data');
        api.ajax({
            url: rootPath+'/api/user/get_user_info',
            method: 'get',
            data: {
                values: { 
                    uid: user.id,
                    token:user.token
                },
            }
        }, function(ret, err) {
            if (ret) {
                if(ret.status == 200) {
                    var head_img = formatHeadImg(ret.data.img);
                    $('.user_head').attr('src',head_img);
                    $('.user_name').text(ret.data.nickname);
                }
            } else {
                
            }
        });
    }

    function fnOpenLogin() {
        api.openFrame({
            name: 'nologin_frame',
            url: 'nologin_frame.html',
            rect: {
                x: 0,
                y: height,
                w: 'auto',
                h: api.winHeight - height - 50
            },
            bounces: false
        });
    }
</script>
</html>